package ipdesk.model.common.action;

import java.util.List;

import ipdesk.model.businessInfo.bean.BusinessInfoBean;
import ipdesk.model.businessInfo.dao.BusinessInfoDao;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;



public class BusinessInfoSelectAction  extends ActionSupport implements Preparable, ModelDriven<BusinessInfoBean>
{
	
	private BusinessInfoBean businessInfoBean;
	private List companyList; 
	private List customerList; 
	private int totalCount;
	
	
	@Override
	public String execute() throws Exception
	{
				
		String deskCode = businessInfoBean.getDeskCode();
		
	
		// 기업정보를 가지고 온다.
		companyList = BusinessInfoDao.getInstance().getCompanyList(deskCode);
		
	
		
		int companySeq = businessInfoBean.getCompanySeq();
		
		
		customerList = BusinessInfoDao.getInstance().getCustomerList(companySeq);
		
	
				
		return SUCCESS;
	}
	
	public String getSearchCompany() throws Exception {
		System.out.println("***"+businessInfoBean.getSearchKeyword());
		System.out.println("***"+businessInfoBean.getAgentFlag());
		totalCount = BusinessInfoDao.getInstance().getSearchCount(businessInfoBean.getSearchKeyword());
		
		companyList = BusinessInfoDao.getInstance().getSearchCompany(businessInfoBean.getSearchKeyword(), businessInfoBean.getAgentFlag());
		
		businessInfoBean.setSearchKeyword(businessInfoBean.getSearchKeyword());
		
		return SUCCESS;
	}
	
	// 담당자 정보를 가져오는 액션 실행메서드
	public String executeGetCustomer() throws Exception
	{
		System.out.println("***"+businessInfoBean.getSearchKeyword());
		System.out.println(businessInfoBean.getCompanySeq());
		totalCount = BusinessInfoDao.getInstance().getSearchCount(businessInfoBean.getSearchKeyword());	
		companyList = BusinessInfoDao.getInstance().getSearchCompany(businessInfoBean.getSearchKeyword(),businessInfoBean.getAgentFlag());
		System.out.println("***"+businessInfoBean.getSearchKeyword());
		int companySeq = businessInfoBean.getCompanySeq();
		System.out.println("번호"+companySeq);
		customerList = BusinessInfoDao.getInstance().getCustomerList(companySeq);
		
		System.out.println(customerList);
		
		return SUCCESS;
	}
	
	
	public void prepare() throws Exception
	{
		businessInfoBean = new BusinessInfoBean();
	}
	
	public BusinessInfoBean getModel()
	{
		return businessInfoBean;
	}

	public List getCompanyList()
	{
		return companyList;
	}

	public void setCompanyList(List companyList)
	{
		this.companyList = companyList;
	}

	public List getCustomerList()
	{
		return customerList;
	}

	public void setCustomerList(List customerList)
	{
		this.customerList = customerList;
	}
	
	public int getTotalCount() {
		return totalCount;
	}


}
